import { forBindEventThis } from '../../../../global_comps/Func/forBindEventThis';
import { upload_file_dataMana } from './cla_upload_file_dataMana';

const upload_file_operateTag = 'upload_file_operate';

export class upload_file_operate extends upload_file_dataMana {
  get [Symbol.toStringTag]() {
    return upload_file_operateTag;
  }

  constructor() {
    super();

    forBindEventThis(this);

    this.eventM.addEventListen(
      this.dom_body,
      'dragenter',
      this.eventBind.dom_body_drag_enter_self
    );

    this.eventM.addEventListen(
      this.dom_body,
      'dragleave',
      this.eventBind.dom_body_drag_leave_self
    );

    this.freeze_drag_leave();

    this.eventM.addEventListen(
      this.dom_body,
      'dragover',
      this.eventBind.dom_body_drag_over
    );

    this.eventM.addEventListen(
      this.dom_body,
      'drop',
      this.eventBind.dom_body_drop
    );

    // 点击 选择 文件
    this.eventM.addEventListen(
      this.dom_body,
      'click',
      this.eventBind.dom_body_click
    );

    // 点击 重新 选择 文件
    this.eventM.addEventListen(
      this.dom_placeholder_operate_change,
      'click',
      this.eventBind.operate_change_click
    );

    // 取消 文件 选中
    this.eventM.addEventListen(
      this.dom_placeholder_operate_cancel,
      'click',
      this.eventBind.operate_cancel_click
    );
  }

  /**
   * 将 文件 扔到 本体元素 上时
   */
  async dom_body_drop(event: DragEvent) {
    event.preventDefault();

    this.drag_file_load(event);

    this.normal_doc();
  }

  /**
   * 点击 元素 上传 文件
   */
  async dom_body_click() {
    let pick_file = await window.showOpenFilePicker();

    await this.click_file_load(pick_file);

    this.normal_doc();
  }

  /**
   * 阻止 over 事件
   */
  dom_body_drag_over(event: DragEvent) {
    event.preventDefault();
  }

  /**
   * 将 文件 进入 本体元素 上时
   */
  dom_body_drag_enter_self() {
    this.freeze_drag_enter();

    // console.log('enter');
  }

  /**
   * 将 文件 进入 本体元素 上时
   */
  dom_body_drag_leave_self() {
    this.freeze_drag_leave();

    // console.log('leave');
  }

  /**
   * 更改 file 信息 记录
   */
  async operate_change_click() {
    let pick_file = await window.showOpenFilePicker();

    await this.click_file_load(pick_file);

    await this.change_file();
  }

  /**
   * 取消 文件信息 记录
   */
  operate_cancel_click() {
    this.remove_file();

    this.special_doc();
  }
}
